package demo.controller.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
public class LoginInterceptor implements Interceptor {

    public void intercept(Invocation invocation) {
        Controller controller=invocation.getController();
        String username=controller.getSessionAttr("username");
        //如果未登入
        if(username==null||username.equals("")){
            System.out.println("未登录");
            controller.setAttr("statusCode",200);
            controller.setAttr("msg","用户未登录");
            controller.redirect(controller.getRequest().getContextPath()+"/all/student/login.html");
        }else {
            invocation.invoke();
        }
    }
}